package my.push;

import java.util.HashMap;
import java.util.Map;

import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.Transport;

/**
 * 后端向前端推送消息
 * @author guojian
 *
 */
public class PushService {

	private static SocketIOServer server = null;

	static {
		Configuration config = new Configuration();
		config.setHostname("191.0.4.96");
		config.setPort(8888);
		config.setTransports(Transport.WEBSOCKET, Transport.POLLING);
		server = new SocketIOServer(config);
		server.start();
	}

	public static SocketIOServer getServer() {
		return server;
	}

	/**
	 * 用户在app上登陆成功后,将位置推送到指挥调度的地图上
	 * @param userName
	 * @param userId
	 * @param x
	 * @param y
	 */
	public static void pushAppLoginLocationToBaiduMap(String userName, String userId, String x, String y, String url) {
		Map<String, String> location = new HashMap<String, String>();
		location.put("x", x);
		location.put("y", y);
		location.put("openId", userId);
		location.put("name", userName);
		location.put("url", url);
		getServer().getBroadcastOperations().sendEvent("appLocation", location);
	}

}
